package com.sq.partner.manager.service.impl;

import com.sq.partner.manager.dao.AntPolicyAndClaimDao;
import com.sq.partner.manager.service.AntPolicyAndClaimService;
import com.sq.partner.manager.util.Page;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

@Service
public class AntPolicyAndClaimServiceImpl implements AntPolicyAndClaimService {
    @Resource
    AntPolicyAndClaimDao antPolicyAndClaimDao;

    @Override
    public Page queryPolicyAndClaim(Page page) throws Exception {
        return antPolicyAndClaimDao.queryPolicyAndClaim(page);
    }

	@Override
	public List<Map<String, Object>> queryPolicyByCondition(Map<String, String> map) throws Exception {
		return antPolicyAndClaimDao.queryPolicyByCondition(map);
	}
	
		@Override
		public HSSFWorkbook generateHssWorkBook(String sheetName, int columnNumber, int[] columnWidth,
		                                        String[] columnName, String[][] haidaInfos) {
			HSSFWorkbook wb = new HSSFWorkbook();
			HSSFSheet sheet = wb.createSheet(sheetName);
			for (int i = 0; i < columnNumber; i++) {
				sheet.setColumnWidth(i, columnWidth[i] * 256);
			}
			HSSFRow headerRow = sheet.createRow(0);
			// 第"0"行行高设置为40
			headerRow.setHeightInPoints(40);
			// 表头单元格样式
			HSSFCellStyle headerStyle = wb.createCellStyle();
			// 设置自动换行
			headerStyle.setWrapText(true);
			// 居中样式
			headerStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
			headerStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
			headerStyle.setBottomBorderColor(HSSFColor.BLACK.index);
			headerStyle.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
			headerStyle.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
			headerStyle.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
			headerStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
			// 设置表头字体样式
			HSSFFont headerFont = wb.createFont();
			headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
			headerFont.setFontName("宋体");
			// 设置字体大小 
			headerFont.setFontHeightInPoints((short) 10);
			headerStyle.setFont(headerFont);
			
			HSSFCell cell = null;
			for (int i = 0; i < columnNumber; i++) {
				cell = headerRow.createCell(i);
				cell.setCellValue(columnName[i]);
				cell.setCellStyle(headerStyle);
			}
			HSSFRow row = null;
			// 数据的样式
			HSSFCellStyle style = wb.createCellStyle();
			style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
			style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
			style.setBottomBorderColor(HSSFColor.BLACK.index);
			style.setBorderBottom(HSSFCellStyle.BORDER_THIN);
			style.setBorderLeft(HSSFCellStyle.BORDER_THIN);
			style.setBorderRight(HSSFCellStyle.BORDER_THIN);
			style.setBorderTop(HSSFCellStyle.BORDER_THIN);
			HSSFFont font = wb.createFont();
			font.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);
			style.setFont(font);
			for (int i = 0; i < haidaInfos.length; i++) {
				row = sheet.createRow(i + 1);
				for (int j = 0; j < columnNumber; j++) {
					cell = row.createCell(j);
					row.setHeightInPoints(16);
					cell.setCellValue(haidaInfos[i][j]);
					cell.setCellStyle(style);
				}
			}
			return wb;
		}
}
